package com.jbm.jbmsupplier.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import com.jbm.jbmsupplier.R;
import com.jbm.jbmsupplier.presenters.TerMinorActivitys;
import com.jbm.jbmsupplier.utlis.ExitActivity;
import com.jbm.jbmsupplier.view.DialogLoading;
import com.jbm.jbmsupplier.views.TerMinorViews;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by 家帮忙 on 2017/4/14.
 */

public class TerMinorActivity extends AllActivityApp implements TerMinorViews {
    @InjectView(R.id.teleft)
    TextView teleft;
    @InjectView(R.id.tetitle)
    TextView tetitle;
    @InjectView(R.id.edzznr)
    EditText edzznr;
    @InjectView(R.id.zzdd)
    Button zzdd;
    String str;
    @InjectView(R.id.spinner)
    Spinner spinner;
    private TerMinorActivitys terMinorActivitys;
    DialogLoading dialogLoading;

    @Override
    public int setContentView() {
        return R.layout.lz_terminor;
    }

    @Override
    public void initIalizeView() {
        ExitActivity.getInstance().addActivity(this);
        ButterKnife.inject(this);
        terMinorActivitys = new TerMinorActivitys(this, this);
        if (getIntent().getStringExtra("tag").equals("1")) {
            tetitle.setText("终止订单");
            str = "终止中....";
            spinner.setVisibility(View.VISIBLE);
        } else if (getIntent().getStringExtra("tag").equals("2")) {
            tetitle.setText("取消订单");
            str = "取消中....";
        }
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String[] languages = getResources().getStringArray(R.array.jiabangmang);
                if (!languages[position].equals("撤单人")) {


                }


            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
    }


    @OnClick({R.id.teleft, R.id.zzdd})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.teleft:
                finish();
                break;
            case R.id.zzdd:
                if (edzznr.getText().toString().equals("")) {
                    hint("内容不可以为空");
                } else if (edzznr.getText().length() > 100) {
                    hint("内容不能超过一百字");
                } else {
                    terMinorActivitys.getTerData(getIntent().getIntExtra("orid", 0), edzznr.getText().toString());
                    dialogLoading = new DialogLoading(this, str, true);
                    dialogLoading.show();
                }
                break;
        }
    }

    @Override
    public void setSucced() {
        Intent inetnt;
        inetnt = new Intent("Isorder");
        inetnt.putExtra("name", "2");
        sendBroadcast(inetnt);
        dialogyc();
        finish();

    }

    @Override
    public void setError(String err) {
        dialogyc();
        hint(err);
    }

    void dialogyc() {
        if (dialogLoading != null) {
            dialogLoading.dismiss();
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.inject(this);
    }
}
